home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / tip / stswitch.tip < prev    next >
Text File  |  1993-09-15  |  2KB  |  58 lines

  1. % This macro source file is from the four volume series
  2. % "TeX in Practice" by Stephan von Bechtolsheim, published
  3. % 1993 by Springer-Verlag, New York.
  4. % Copyright 1993 Stephan von Bechtolsheim.
  5. % No warranty or liability is assumed.
  6. % This macro may be copied freely if no fees other than
  7. % media cost or shipping charges are charged and as long
  8. % as this copyright and the following source code itself
  9. % is not changed. Please see the series for further information.
  10. %
  11. % Version: 1.0
  12. % Date: May 1, 1993
  13. %
  14. %
  15. % This source code is documented in 25.1.19.1, p. III-341.
  16. % Original source in file "macros5.TEX", starting line 1398.
  17. \wlog{L: "stswitch.tip" ["macros5.TEX," l. 1398, p. III-341]}%
  18. % This file DOES belong to format "texip."
  19. \InputD{compst.tip}
  20. \catcode`\@ = 11
  21. \newcount\@StringSwitchMatchCount
  22. \def\StringSwitch #1#2{%
  23.     \edef\@StringSwitchMasterString{#1}%
  24.     \if\EmptyStringConditional{#1}%
  25.         \errmessage{\string\StringSwitch: master string
  26.             must not be the empty string.}%
  27.     \fi
  28.     \def\@StringSwitchMatchCommonCode{#2}%
  29.     \@StringSwitchMatchCount = 0
  30.     \@StringSwitch  
  31. }
  32. \def\@StringSwitchOne #1#2{%
  33.     \def\@StringSwitchString{#1}%
  34.     \def\@StringSwitchAction{#2}%
  35. }
  36. \def\@StringSwitch #1{%
  37.     \@StringSwitchOne #1%
  38.     \if\EmptyStringConditional{\@StringSwitchString}%
  39.         \ifcase\@StringSwitchMatchCount
  40.             \@StringSwitchAction
  41.         \or
  42.         \else
  43.             \errmessage{\string\StringSwitch: double match.}%
  44.         \fi
  45.         \def\@StringSwitchNext{}%
  46.     \else
  47.         \if\StringsEqualConditional{\@StringSwitchMasterString}%
  48.             {\@StringSwitchString}%
  49.             \advance\@StringSwitchMatchCount by 1
  50.             \@StringSwitchMatchCommonCode
  51.             \@StringSwitchAction
  52.         \fi
  53.         \def\@StringSwitchNext{\@StringSwitch}%
  54.     \fi 
  55.     \@StringSwitchNext
  56. }
  57. \catcode`\@ = 12
  58.